package com.xjgz.smart.demo;

import org.smartboot.socket.MessageProcessor;
import org.smartboot.socket.transport.AioQuickServer;
import org.smartboot.socket.transport.WriteBuffer;

import java.io.IOException;

public class StringServer {

    public static void main(String[] args) throws IOException {
        MessageProcessor<String> processor = (session, msg) -> {
            System.out.println("receive from client: " + msg);
            WriteBuffer outputStream = session.writeBuffer();
            try {
                byte[] bytes = msg.getBytes();
                outputStream.writeInt(bytes.length);
                outputStream.write(bytes);
            } catch (IOException e) {
                e.printStackTrace();
            }
        };

        AioQuickServer server = new AioQuickServer(8888, new StringProtocol(), processor);
        server.setBannerEnabled(false);
        server.start();
    }
}